package com.dzf.util;

import com.alibaba.nacos.common.http.HttpUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dzf.entity.MyUser;
import com.dzf.mapper.UserMapper;
import com.dzf.service.impl.LoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

@Component
public class SessionUtil {
    @Autowired
    LoginServiceImpl loginService;

    public  MyUser getUser()
    {
        String principal = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        MyUser user;
        if (principal==null)
        {
            return null;
        }else{
             user = (MyUser) loginService.loadUserByUsername(principal);
        }


        return  user;
    }
}
